<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/mb/jsp/common.jsp" %>
<%@ page import="com.limao.CacheManager.CrowdSysProjectCache" %>
<%@ page import="com.limao.DBDataClass.CrowdProjectBuyClass" %>
<%@ page import="com.limao.DBDataClass.CrowdSysDiscussDataClass" %>
<%@ page import="com.limao.DBDataClass.CrowdSysProjectClass" %>
<%@ page import="com.limao.Model.PublicData" %>
<%@ page import="com.limao.servlet.WebFunction" %>
<%@ page import="com.wsu.search.tools.Tools" %>

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>商品详情</title>

</head>
<body ontouchstart="">
<div class="detailTop pf w100 of">
    <div class="w100 of tc c3 f18">
        <span class="pa" style="left: 2px;" onclick="javascript:history.back();"><img src="mb/images/top_back.png"
                                                                                      style="margin-top: 4px;height: 40px;width: 40px;"/></span>
        商品详情
        <!-- <div class="dib of pa" style="right: 10px;">
            <a href="mb/riskWarning.html" class="dib tc">退货说明</a>
        </div> -->
    </div>
</div>


<div id="container" class="container jz">

</div><!--container  -->


<div class="detailBottm pf w100 of">
    
    <div class="w100 of clearfix">
    	<div class="fl" style="width:49.6%;">
		    <div class="addMin clearfix of w100">
			    <input id="min" name="" type="button" value="-"  style="width:20%;height:40px;"/>  
				<input id="text_box" name="" type="text" value="1" onkeyup="this.value=(this.value.match(/\d?/)||[''])[0]" style="width:60%;height:38px;"/>  
				<input id="add" name="" type="button" value="+" style="width:20%;height:40px;"/>  
			</div>
    	</div>
    	<div class="fr" style="width:49.6%;">
		   <a href="javascript:buySth(prestigeid,$('#text_box').val());" class="db f18 cf f18 tc w100">购&nbsp;买</a>
    	</div>
    </div>
</div>

<script>
	//获取url中的参数
        function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
            var r = window.location.search.substr(1).match(reg);  //匹配目标参数
            if (r != null) return unescape(r[2]); return null; //返回参数值
        }
     var prestigeid = getUrlParam('prestigeid');
         
     
     // 加载新数据
    function getData(prestigeid) {
        $.ajax({
            url: "PlugServlet",
            data: JSON.stringify({m: 1678,prestigeid:prestigeid}),
            type: 'post',
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            beforeSend: function () {
                  
            },
            success: function (data) {
 				console.log(data.obj);
               if (data.state == 1) {
                  showData(data.obj);
                } else {
                    // 其他错误弹出提示
                    showToast(data.info);
                }
            },
            error: function (data) {
                showToast(data.info);
            },
            complete: function () {
                closeProgressDg();
            }
        });
    }
    
    //插入数据
    function showData(obj)
    {
   		var tmpimg = obj.prestigeimage.split(';');
   		var introimage = obj.introimage.split(';');
   		if(obj.prestigeintro == ""||obj.prestigeintro == undefined||obj.prestigeintro == null){
   		   obj.prestigeintro = "暂无";
   		};
   		var imgList = "";
   		var dotList = "";
   		 var imgDetailList = "";
   		for (var i = 0; i < tmpimg.length; i++) {
   		
   			imgList += '<li style="float: none; display: block; position: absolute; top: 0px; left: 0px; width: 375px;"><span style="background:url('+getBaseImgUrl(tmpimg[i])+') center top no-repeat;background-size: cover" ;=""></span></li>';
   		    imgDetailList += '<img src="'+getBaseImgUrl(introimage[i])+'" class="w100 hauto" style="margin-bottom: 7px;">'
   		}
   		
   		if(tmpimg.length == 1){
   			dotList = "";
   		}
   		else{
	   		for (var i = 0; i < tmpimg.length; i++) {
	   		    dotList += '<a href="#" class="">' + i +'</a>';
	   		}
   		}
   		
   		 	
   		var htmlStr = '<div id="imgContainer" class="main_visual_detail">'+
	   					'<div class="flicking_con w100">'+
				            '<div class="dib jz">'+
				              dotList+
				            '</div>'+
				
				        '</div>'+
				
				        '<div class="main_image_detail">'+
				            '<ul style="width: 375px; overflow: visible;">'+
								imgList +
				            '</ul>'+
				        '</div>'+
			        '</div>'+
			        '<!--main_visual_detail-->'+
			        '<section class="proSection pr w100 bcf mggt10" style="padding-bottom: 3px;">'+
				         '<div style="margin-left:3%;">'+
					         '<h5 class="c3 f13 mgt10 lh2">'+ obj.prestigename +'</h5>'+
					         '<p class="c6 f12 lh2">狸猫豆：'+obj.requirevalue+'&nbsp;&nbsp;&nbsp;&nbsp;市场价：<span class="lineThroughSpan">'+obj.oldprice+'</span></p>'+
					         '<p class="c6 f12 lh18">回购价：'+obj.callbackprice+'</p>'+
					         '<p class="c6 f12 lh18" style="margin-top: 3px;">已售：'+obj.buynum+'</p>'+
				         '</div>'+
				    '</section>'+
				     '<section class="proSection pr w100 bcf">'+
				        '<div class="detailCompany w100">'+
				            '<h4 class="f14 c3 jz">商品简介</h4>'+
				            '<p class="detailInfo c9 f12 jz">'+
				                 obj.prestigeintro +
				            '</p>'+
				        '</div>'+
				    '</section>'+
			        '<div id="introDetail" class="w100 of bcf">'+
				        '<div>'+
				            '<ul class="introTab">'+
				                '<li class="introtab_current"><span>图片简介</span></li>'+
				            '</ul>'+
				        '</div>'+
				       '<div class="introtab_content">'+
				            '<article style="display:block;">'+
				                imgDetailList +
				            '</article><!--产品-->'+
				
				        '</div>'+
				    '</div>';
   		   
       	
    	 $("#container").html(htmlStr);
    	 scollImg();
    }
 
function scollImg(){
 //            图片滑动
            $dragBln = false;
            $(".main_image_detail").touchSlider({
                flexible: true,
                speed: 200,
                btn_prev: $("#btn_prev"),
                btn_next: $("#btn_next"),
                paging: $(".flicking_con a"),
                counter: function (e) {
                    $(".flicking_con a").removeClass("on").eq(e.current - 1).addClass("on");
                }
            });

            $(".main_image_detail").bind("mousedown", function () {
                $dragBln = false;
            });

            $(".main_image_detail").bind("dragstart", function () {
                $dragBln = true;
            });

            $(".main_image_detail a").click(function () {
                if ($dragBln) {
                    return false;
                }
            });
            $(".main_visual_detail").hover(function () {
//                clearInterval(timer);
            }, function () {
                timer = setInterval(function () {
                    $("#btn_next").click();
                }, 5000);
            });

            $(".main_image_detail").bind("touchstart", function () {
                clearInterval(timer);
            }).bind("touchend", function () {
                timer = setInterval(function () {
                    $("#btn_next").click();
                }, 5000);
            });
            
}
  // 购买
    function buySth(prestigeid,num) {
        $.ajax({
            url: "PlugServlet",
            data: JSON.stringify({m: 1672,prestigeid:prestigeid,num:num}),
            type: 'post',
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            beforeSend: function () {

            },
            success: function (data) {
 				console.log(data);
               if (data.state == 1) {
                  // 成功弹出提示
                  showToast(data.info);
                } else {
                    // 其他错误弹出提示
                    showToast(data.info);
                }
            },
            error: function (data) {
                showToast(data.info);
            },
            complete: function () {
                closeProgressDg();
                setTimeout('window.history.back()', 2000); 
            }
        });
    }

$(document).ready(function () {
 
       
          getData(prestigeid); 

       //获得文本框对象
		   var t = $("#text_box");
		 
		//初始化数量为1,并失效减
		$('#min').attr('disabled',true);
	    //数量增加操作
	    $("#add").click(function(){    
	        t.val(parseInt(t.val())+1)
	        if (parseInt(t.val())!=1){
	            $('#min').attr('disabled',false);
	        }
	    }) 
	    //数量减少操作
	    $("#min").click(function(){
	        t.val(parseInt(t.val())-1);
	        if (parseInt(t.val())==1){
	            $('#min').attr('disabled',true);
	        }
	    })

});
        
	</script> 
</body>
</html>